/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * <p>Project: javase2203 - T21
 * <p>Powered by webrx On 2022-08-10 14:37:57
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class T22 {
    static CountDownLatch latch = new CountDownLatch(100);
    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            new Thread(() -> {
                String t = Thread.currentThread().getName();
                System.out.printf("%s:线程启动....%n",t);
                Random rand = new Random();
                try {
                    TimeUnit.SECONDS.sleep(rand.nextInt(1, 5));
                } catch (Exception e) {
                    e.printStackTrace();
                }
                System.out.printf("%s:结束了%n",t);
                latch.countDown();
            }, "T" + i).start();

        }

        try {
            latch.await();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("main：大结局...");
    }
}
